<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/6/25 10:23
 * Modified Time: 2019/6/25 10:23
 * Version: 2.0
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Store extends Model
{
    use SoftDeletes;
    protected $table = 'store';

    protected $guarded = [];

	public function user(){
		return $this->belongsToMany(User::class,'user_store', 'sid','uid' )->withPivot('rid', 'is_work','is_default');
//		return $this->belongsToMany(User::class,'user_store', 'sid','uid' );
	}

	public function logo(){
	    return $this->hasOne(Picture::class,'id','logo');
    }

	public function storeResource(){
	    return $this->hasMany(StoreResource::class,'store_id','id');
    }
	public function city(){
		return $this->hasOne(City::class, 'code', 'adcode');
	}

	public function comment(){
        return $this->hasMany(OrderComment::class,'store_id','id');
    }

    public function storeLike(){
		return $this->hasMany(StoreLike::class, 'store_id','id');
    }

    public function picture(){
		return $this->hasOne(Picture::class,'id','logo');
    }


    public function userStore(){
		return $this->hasMany(UserStore::class, 'sid','id');
    }

    public function storeRank(){
		return $this->hasMany(StoreRank::class,'store_id','id');
    }

    public function alipay(){
        return $this->hasOne(Picture::class,'id','alipay');
    }

    public function wxpay(){
        return $this->hasOne(Picture::class,'id','wxpay');
    }

    public function photo(){
        return $this->hasMany(StorePhoto::class,'store_id','id');
    }
}